﻿<Window x:Class="Lds.Ward.PhotoDirectory.WpfApp.MainWindow"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:av="clr-namespace:Avalon.Windows.Controls;assembly=AvalonLibrary"
	xmlns:logic="clr-namespace:Lds.Ward.PhotoDirectory.Logic;assembly=WardPhotoDirectoryLogic"
	xmlns:app="clr-namespace:Lds.Ward.PhotoDirectory.WpfApp"
	Title="Ward Photo Directory" Height="372" Width="600">
	<Window.Resources>
		<logic:Families x:Key="familiesCollection" />
		<DataTemplate x:Key="FamilyFilterColumn">
			<CheckBox IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" />
		</DataTemplate>
		<DataTemplate x:Key="FamilyNameColumn">
			<TextBlock Text="{Binding Surname}" />
		</DataTemplate>
		<DataTemplate x:Key="FamilyMembersColumn">
			<ItemsControl ItemsSource="{Binding FamilyMembers}">
				<ItemsControl.ItemTemplate>
					<DataTemplate>
						<TextBlock Text="{Binding GivenNames}" />
					</DataTemplate>
				</ItemsControl.ItemTemplate>
			</ItemsControl>
		</DataTemplate>
		<DataTemplate x:Key="AddressColumn">
			<TextBlock Text="{Binding MailingAddress}" />
		</DataTemplate>
		<DataTemplate x:Key="photoTile">
			<StackPanel>
				<Image Source="{Binding ImagePath}" ToolTip="{Binding ToolTip}"
				       Height="60" Margin="3,3,3,0" HorizontalAlignment="Center" />
				<TextBlock Text="{Binding Surname}" 
				           FontSize="13" Margin="5,2,5,1" HorizontalAlignment="Center" />
			</StackPanel>
		</DataTemplate>
	</Window.Resources>
	<Grid Margin="5">
		<Grid.RowDefinitions>
			<RowDefinition/>
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto"/>
			<ColumnDefinition Width="*" />
			<ColumnDefinition Width="Auto" />
		</Grid.ColumnDefinitions>
		<TabControl Grid.ColumnSpan="3" Margin="0,0,0,5" x:Name="tabs">
			<TabItem Header="MLS Import">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition/>
						<ColumnDefinition/>
						<ColumnDefinition/>
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition Height="auto"/>
						<RowDefinition Height="auto"/>
						<RowDefinition Height="auto"/>
						<RowDefinition Height="auto"/>
						<RowDefinition/>
					</Grid.RowDefinitions>
					<StackPanel Grid.ColumnSpan="3">
						<TextBlock TextWrapping="Wrap">
							Import the membership records from the Church MLS program 
							database into this program to produce the ward photo 
							directory.
						</TextBlock>
						<TextBlock TextWrapping="Wrap" Margin="0,0,0,15">
							You may import the MLS data in either of the following 
							two ways:
						</TextBlock>
					</StackPanel>

					<TextBlock Grid.Row="1" TextWrapping="Wrap" Text="Import from file" />
					<TextBlock Grid.Row="1" Grid.Column="1" x:Name="importedFilename" Text="[none selected]" />
					<Button Grid.Row="1" Grid.Column="2" Command="Open">
						<StackPanel Orientation="Horizontal">
							<Image />
							<TextBlock>Browse...</TextBlock>
						</StackPanel>
					</Button>
					
					<TextBlock Grid.Row="2" TextWrapping="Wrap" Text="Import from clipboard" />
					<TextBlock Grid.Row="2" Grid.Column="1" x:Name="clipboardCopy" TextWrapping="Wrap">
						You must first go to MLS and select "Copy to clipboard"
					</TextBlock>
					<av:NotifyIcon x:Name="MlsCopyClipboardNotifyIcon" Icon="images/copy.ico" Visibility="Hidden"
								   BalloonTipTitle="Export MLS Data">
						<av:NotifyIcon.BalloonTipText>
								In the MLS program:\n
								1) Within the MLS tab, within the Directories section,\n
								2) Click "Directory of Members"\n
								3) Click the Edit menu, and choose either "Copy to file" or "Copy to clipboard".
						</av:NotifyIcon.BalloonTipText>
						<av:NotifyIcon.ContextMenu>
							<ContextMenu>
								<MenuItem Header="Tell me again" Click="showNotifyPrompt_Click"/>
								<MenuItem Header="Cancel and return to program" Click="cancelPasteButton_Click"/>
							</ContextMenu>
						</av:NotifyIcon.ContextMenu>
					</av:NotifyIcon>
					<Button Grid.Row="2" Grid.Column="2" Command="Paste">
						<StackPanel Orientation="Horizontal">
							<Image Source="images/pastehs.png" Height="16" Width="16" />
							<TextBlock VerticalAlignment="Center">Paste</TextBlock>
						</StackPanel>
					</Button>
					
					<TextBlock Grid.Row="3" TextWrapping="Wrap" Text="Membership records imported:" />
					<TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding Source={StaticResource familiesCollection}, Path=Count}" />
					
					<StackPanel Grid.Row="4" Grid.ColumnSpan="3" VerticalAlignment="Bottom">
						<TextBlock TextWrapping="Wrap">
							To prepare your MLS membership directory for export into this program:
						</TextBlock>
						<TextBlock TextWrapping="Wrap">
							1) Within the MLS tab, within the Directories section,
						</TextBlock>
						<TextBlock TextWrapping="Wrap">
							2) Click "Directory of Members"
						</TextBlock>
						<TextBlock TextWrapping="Wrap">
							3) Click the Edit menu, and choose either "Copy to file" or "Copy to clipboard".							
						</TextBlock>
					</StackPanel>
				</Grid>
			</TabItem>
			<TabItem Header="Photos">
				<DockPanel LastChildFill="True">
					<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top">
						Use digital pictures you have already taken to assemble your ward photo directory.  
						You should store all your digital pictures of ward memers in the same directory, and 
						follow some unique naming convention for all your photos.
					</TextBlock>
					<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top">
						An acceptable naming convention might be: Lastname, Firstname.jpg
					</TextBlock>
					<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top">
						If you have a photo of an entire family, use the first name of the head of household.
					</TextBlock>
					<WrapPanel DockPanel.Dock="Top">
						<TextBlock TextWrapping="Wrap">
							Indicate the directory where you save your photos:
						</TextBlock>
						<TextBlock x:Name="photoDirectoryLabel" Text="[none]" Margin="5,0,5,0"/>
						<Button Command="{x:Static app:MainWindow.BrowsePhotoFolders}">
							<StackPanel Orientation="Horizontal">
								<Image/>
								<TextBlock>Browse...</TextBlock>
							</StackPanel>
						</Button>
					</WrapPanel>
				</DockPanel>
			</TabItem>
			<TabItem Header="Details">
				<StackPanel>
					<StackPanel Orientation="Horizontal">
						<Label>Name of unit</Label>
						<TextBox/>
					</StackPanel>
					<StackPanel Orientation="Horizontal">
						<Label>Photo board picture width</Label>
						<TextBox/>
						<ComboBox>
							<ComboBox.Items>
								<ComboBoxItem>in</ComboBoxItem>
								<ComboBoxItem>cm</ComboBoxItem>
								<ComboBoxItem>mm</ComboBoxItem>
							</ComboBox.Items>
						</ComboBox>
					</StackPanel>

					<GroupBox Header="Hide">
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="Auto"/>
								<ColumnDefinition/>
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition/>
								<RowDefinition/>
								<RowDefinition/>
								<RowDefinition/>
								<RowDefinition/>
							</Grid.RowDefinitions>
							<TextBlock TextWrapping="Wrap" Grid.ColumnSpan="2">
								To avoid certain common information from showing up in the ward directory,
								enter the information to hide here.
							</TextBlock>

							<Label Grid.Row="1">Area code</Label>
							<TextBox Grid.Row="1" Grid.Column="1" x:Name="hideAreaCodeBox"/>
							<Label Grid.Row="2">City</Label>
							<TextBox Grid.Row="2" Grid.Column="1" x:Name="hideCityBox"/>
							<Label Grid.Row="3">State</Label>
							<TextBox Grid.Row="3" Grid.Column="1" x:Name="hideStateBox"/>
							<Label Grid.Row="4">Zip</Label>
							<TextBox Grid.Row="4" Grid.Column="1" x:Name="hideZipCodeBox"/>
						</Grid>
					</GroupBox>

				</StackPanel>
			</TabItem>
			<TabItem Header="Filter">
				<Grid>
					<Grid.ColumnDefinitions>
						<ColumnDefinition/>
						<ColumnDefinition Width="Auto"/>
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto"/>
						<RowDefinition/>
					</Grid.RowDefinitions>
					<Label>Select which families to include:</Label>
					<ToolBar Grid.Column="1">
						<Button Content="Select All" Command="SelectAll" Focusable="False" />
						<Button Content="Clear All" Command="{x:Static app:MainWindow.UnselectAll}" Focusable="False" />
					</ToolBar>
					<ListView Grid.Row="1" Grid.ColumnSpan="2" SelectionMode="Multiple"
							  x:Name="familyFilterListView"
							  ItemsSource="{Binding Source={StaticResource familiesCollection}}">
						<ListView.View>
							<GridView>
								<GridViewColumn CellTemplate="{StaticResource FamilyFilterColumn}" />
								<GridViewColumn Header="Family" CellTemplate="{StaticResource FamilyNameColumn}" />
								<GridViewColumn Header="Members" CellTemplate="{StaticResource FamilyMembersColumn}"/>
								<GridViewColumn Header="Address" CellTemplate="{StaticResource AddressColumn}" />
							</GridView>
						</ListView.View>
					</ListView>
				</Grid>
			</TabItem>
			<TabItem Header="Preview">
				<DockPanel LastChildFill="True">
					<ToolBar DockPanel.Dock="Top">
						<Button Command="{x:Static app:MainWindow.ExportPhotos}" ToolTip="Save As">
							<Image Source="images/saveHS.png" Width="16" Height="16" />
						</Button>
						<Button Command="Print" ToolTip="Print">
							<Image Source="images/PrintHS.png" Width="16" Height="16" />
						</Button>
						<!--<Button Command="{x:Static app:MainWindow.ExportPhotos}" CommandParameter="{x:Static app:ExportTarget.PhotoDirectory}">
							<StackPanel>
								<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center">
									Photo directory
								</TextBlock>
							</StackPanel>
						</Button>
						<Button Command="{x:Static app:MainWindow.ExportPhotos}" CommandParameter="{x:Static app:ExportTarget.BulletinBoardPhotos}">
							<StackPanel>
								<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center">
									Produce bulletin board pictures
								</TextBlock>
							</StackPanel>
						</Button>-->
						<Button Command="{x:Static app:MainWindow.ExportPhotos}" CommandParameter="{x:Static app:ExportTarget.WebSite}" ToolTip="Upload to ward web site">
							<StackPanel Orientation="Horizontal">
								<Image Source="images/Network_Internet.png" Width="16" Height="16" />
								<TextBlock>Upload to ward web site</TextBlock>
							</StackPanel>
						</Button>
					</ToolBar>
					<Grid DockPanel.Dock="Right" Width="150">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="*"/>
							<ColumnDefinition Width="*"/>
							<ColumnDefinition Width="*"/>
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto"/>
							<RowDefinition Height="*"/>
							<RowDefinition Height="Auto"/>
							<RowDefinition Height="Auto"/>
						</Grid.RowDefinitions>

						<TextBlock Grid.Column="0" Grid.Row="0" TextAlignment="Center" TextWrapping="Wrap">Larger photos</TextBlock>
						<Slider Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center" Orientation="Vertical" Minimum="1" SmallChange="1" LargeChange="2" Value="5" />
						<TextBlock Grid.Column="0" Grid.Row="2" TextAlignment="Center" TextWrapping="Wrap">Larger text</TextBlock>

						<TextBlock Grid.Column="1" Grid.Row="0" TextAlignment="Center" TextWrapping="Wrap">More photos</TextBlock>
						<Slider Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" Orientation="Vertical" TickPlacement="BottomRight" TickFrequency="1" Minimum="1" Maximum="20" Value="9" SmallChange="1" LargeChange="3" IsSnapToTickEnabled="True" />
						<TextBlock Grid.Column="1" Grid.Row="2" TextAlignment="Center" TextWrapping="Wrap">Fewer photos</TextBlock>

						<TextBlock Grid.Column="2" Grid.Row="0" TextAlignment="Center" TextWrapping="Wrap">Higher quality</TextBlock>
						<Slider Grid.Column="2" Grid.Row="1" HorizontalAlignment="Center" Orientation="Vertical" TickPlacement="BottomRight" TickFrequency="10" Minimum="20" Maximum="100" Value="60" SmallChange="5" LargeChange="20" IsSnapToTickEnabled="True" />
						<TextBlock Grid.Column="2" Grid.Row="2" TextAlignment="Center" TextWrapping="Wrap">Lower quality</TextBlock>

						<ComboBox Grid.Row="3" Grid.ColumnSpan="3" SelectedIndex="0">
							<ComboBox.Items>
								<Label>Landscape</Label>
								<Label>Portrait</Label>
							</ComboBox.Items>
						</ComboBox>
					</Grid>
					<FlowDocumentPageViewer DockPanel.Dock="Top" x:Name="flowDocumentPageViewer" Height="100">
						<FlowDocumentPageViewer.Document>
							<FlowDocument>
								<Paragraph>
									[TODO: Make this be the data-bound families and photos]
								</Paragraph>
							</FlowDocument>
						</FlowDocumentPageViewer.Document>
					</FlowDocumentPageViewer>
					<ListView ItemsSource="{Binding Source={StaticResource familiesCollection}}">
						<ListView.View>
							<app:PlainView ItemTemplate="{StaticResource photoTile}" />
						</ListView.View>
					</ListView>
				</DockPanel>
			</TabItem>
		</TabControl>
		<Button Grid.Row="1" Command="Save">
			<StackPanel Orientation="Horizontal">
				<Image Source="images/SaveHS.png" Height="16"/>
				<Label>_Save for later</Label>
			</StackPanel>
		</Button>
		<Label Grid.Row="1" Grid.Column="1" Foreground="Green" FontWeight="Bold"
			   Visibility="Hidden" x:Name="workingLabel"
			   HorizontalAlignment="Center" VerticalAlignment="Center" Content="Working..." />
		<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="2" Margin="24.766,0,0,0">
			<Button Command="{x:Static app:MainWindow.PreviousStep}">
				<StackPanel Orientation="Horizontal">
					<Image Source="images/DataContainer_MovePreviousHS.png" Height="16"/>
					<Label>_Back</Label>
				</StackPanel>
			</Button>
			<Button Command="{x:Static app:MainWindow.NextStep}">
				<StackPanel Orientation="Horizontal">
					<Image Source="images/DataContainer_MoveNextHS.png" Height="16"/>
					<Label>_Next</Label>
				</StackPanel>
			</Button>
			<Button Command="{x:Static app:MainWindow.SkipToEnd}">
				<StackPanel Orientation="Horizontal">
					<Image Source="images/DataContainer_MoveLastHS.png" Height="16"/>
					<Label>_Finish</Label>
				</StackPanel>
			</Button>
		</StackPanel>
	</Grid>
</Window>
